package com.example.hello.controller;

import com.example.hello.pojo.Emp;
import com.example.hello.pojo.Result;
import com.example.hello.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController// @Controller + @ResponseBody
public class EmpController {

    @Autowired//运行时，IOC容器会自动注入该类型的bean对象，并赋值给该变量，-依赖注入
    @Qualifier("empServiceA")
    private EmpService empService;

    /*@Resource(name="empServiceB")
    private EmpService empService;*/

    @RequestMapping("/listEmp")
    public Result list(){
        //调用service,获取数据
        List<Emp> empList = empService.listEmp();
        //3.response data
        return Result.success(empList);
    }

    /*@RequestMapping("/listEmp")
    public Result list(){
        //1.加载解析emp.xml
        String file=this.getClass().getClassLoader().getResource("emp.xml").getFile();
        System.out.println(file);
        List<Emp> empList = XmlParserUtils.parse(file, Emp.class);
        //2.对数据进行转换处理
        empList.stream().forEach(emp->{
            //处理每一个字段
            //先处理gender 1man 2 woman
            String gender = emp.getGender();
            if (gender.equals("1")){
                emp.setGender("男");
            }else if (gender.equals("2")){
                emp.setGender("女");
            }
            //处理job 1讲师，2班主任 3就业指导
            String job = emp.getJob();
            if (job.equals("1")){
                emp.setJob("讲师");
            }else if (job.equals("2")){
                emp.setJob("班主任");
            }else if (job.equals("3")){
                emp.setJob("就业指导");
            }
        });
        //3.response data
        return Result.success(empList);
    }*/
}
